//
//  StroeManageView.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/6/2.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "StroeManageView.h"
#import "StringTool.h"
#import <CoreGraphics/CoreGraphics.h>
#import "config.h"

@interface StroeManageView()
@property (weak, nonatomic) IBOutlet UIView *leftView;

@property (weak, nonatomic) IBOutlet UIButton *selecteStatuBtn;

@property (weak, nonatomic) IBOutlet UILabel *storeNameLab;
@property (weak, nonatomic) IBOutlet UILabel *brokerNumLab;
@property (weak, nonatomic) IBOutlet UILabel *moneyLab;
@property (weak, nonatomic) IBOutlet UILabel *tiplab;
@property (weak, nonatomic) IBOutlet UIView *rightView;

@property(strong, nonatomic)NSLayoutConstraint *conLay;
@end
@implementation StroeManageView

+(instancetype)createView
{
    StroeManageView *view = [[[NSBundle mainBundle]loadNibNamed:@"StroeManageView" owner:nil options:nil]lastObject];
    
    
    for (NSLayoutConstraint * conLay in view.constraints) {
        if (conLay.firstItem == view.leftView && conLay.firstAttribute == NSLayoutAttributeLeading) {
            view.conLay = conLay;
            break;
        }
    }
    
    return view;
}

-(void)setModel:(StoreInfoModel *)model
{
    _model = model;
    if (![StringTool isBlankString:model.storeName]) {
        self.storeNameLab.text = model.storeName;
    }
   
    if (model.brokeCounts >=0) {
        self.brokerNumLab.text = [NSString stringWithFormat:@"经纪人 %zd",model.brokeCounts];
    }
    if (![StringTool isBlankString:model.brokerages]) {
         NSMutableAttributedString *AttributedSt = [self dealStr:[NSString stringWithFormat:@"佣金:$ %@",model.brokerages]];
        self.moneyLab.attributedText = AttributedSt;
    }else
    {
        NSMutableAttributedString *AttributedSt = [self dealStr:[NSString stringWithFormat:@"佣金:$ 0"]];
        self.moneyLab.attributedText = AttributedSt;

    }
    self.tiplab.hidden = model.status == 0?YES:NO;
    [self.selecteStatuBtn setHighlighted:model.isSeleted];
}
-(void)setIsEditMode:(BOOL)isEditMode
{
        
    [self.rightView setHidden:isEditMode];
        
    self.conLay.constant = isEditMode?30:10;
    self.selecteStatuBtn.hidden = !isEditMode;
//    self.backBtn.enabled = !isEditMode;
    
    [self layoutIfNeeded];
    
    
}

-( NSMutableAttributedString *)dealStr:(NSString *)str
{
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str];
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:UIColorFromRGB(0x333333)
     
                          range:NSMakeRange(3, 1)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
     
                          value:UIColorFromRGB(0x0084C8)
     
                          range:NSMakeRange(0, 3)];
    
    return AttributedStr;

}
@end
